home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / pascal / tpb4_src.zip / SYSOP2.PAS < prev    next >
Pascal/Delphi Source File  |  1988-09-14  |  19KB  |  584 lines

  1. { TPBoard 4.2 Copyright (c) 1987,88 by Jon Schneider & Rick Petersen  
  2.   Portions Copyright (c) 1986,87 by Steve Fox and Les Archambault  
  3.   
  4.   Last modified  ::  9-5-88 12:35 pm 
  5. }
  6.  
  7. {$R-}                             {Range checking off}
  8. {$B-}                             {Boolean complete evaluation off}
  9. {$S-}                             {Stack checking off}
  10. {$I+}                             {I/O checking on}
  11. {$N-}                             {No numeric coprocessor}
  12.  
  13. Unit Sysop2;
  14.  
  15. Interface
  16.  
  17. Uses
  18.   TPCrt, Dos, Globals, TAccess, Core1,
  19.   Core2, TPDos, TPSTRING, Dirs, MsgMisc,
  20.   Sysop1, Sort;
  21.   
  22.   
  23. procedure sys_dir;
  24.  
  25. procedure purge_files;
  26.  
  27.  
  28.   {==========================================================================}
  29.   
  30.   
  31. Implementation
  32.  
  33.  
  34.   procedure sys_dir;
  35.     { Create system directory file }
  36.     
  37.   var
  38.     TmpDrv, KepDrv  : Str3;
  39.     This            : SectPtr;
  40.     DestName        : DosFileName;
  41.     t               : tad_array;
  42.     KepReq          : Str10;
  43.     Str             : StrTAD;
  44.     TmpName,
  45.     KepName         : StrPr;
  46.     not_found       : Integer;
  47.     
  48.     procedure write_list;
  49.       { write list of files in current section }
  50.       
  51.     var
  52.       Str             : string;
  53.       i               : LongInt;
  54.       Dirspec         : StrPr;
  55.       key, SearchKey  : DosFileName;
  56.       need_sort       : Boolean;
  57.       
  58.       procedure write_rec;
  59.       
  60.       begin
  61.         with nwin_rec do
  62.           begin
  63.             not_found := 0;
  64.             Str := pad(name, 15);
  65.             Write(sort_file, Str);
  66.             if CreditType = Points then
  67.               WriteLn(sort_file, '    Cost: ', PointValue, ' Points')
  68.             else
  69.               WriteLn(sort_file);
  70.             WriteLn(sort_file, '    ', descr);
  71.           end;
  72.       end;
  73.       
  74.     begin
  75.       abort := False;
  76.       Dirspec := SetName;
  77.       WriteLn(dir_file);
  78.       WriteLn(dir_file);
  79.       WriteLn(dir_file, 'File area: ', SectReq, '   (', This^.SectDesc, ')');
  80.       WriteLn(dir_file);
  81.       Assign(sort_file, 'SORT.TMP');
  82.       Rewrite(sort_file);
  83.       need_sort := False;
  84.       if SectReq = 'NEWIN' then
  85.         begin
  86.           not_found := 0;
  87.           i := Pred(FileSize(nwin_file));
  88.           while (not brk) and (i >= 0) do
  89.             begin
  90.               Seek(nwin_file, i);
  91.               Read(nwin_file, nwin_rec);
  92.               with nwin_rec do
  93.                 begin
  94.                   if (status = public) and (ExistFile(Dirspec+'\'+name)) then
  95.                     begin
  96.                       write_rec;
  97.                       need_sort := True;
  98.                     end
  99.                   else
  100.                     begin
  101.                       Inc(not_found);
  102.                       if not_found > 100 then
  103.                         i := 0;
  104.                     end;
  105.                 end;
  106.               i := Pred(i);
  107.             end;
  108.           Close(sort_file);
  109.           if need_sort then
  110.             not_found := TurboSort(SizeOf(sort_rec), @put_recs, @less_rec, @get_recs)
  111.           else
  112.             begin
  113.               Close(sort_file);
  114.               Erase(sort_file);
  115.             end;
  116.           if FileSize(nwin_file) = 0 then
  117.             WriteLn(Com, 'Newin List is empty.');
  118.         end
  119.       else
  120.         begin
  121.           SearchKey := SectReq;
  122.           key := SectReq;
  123.           FindKey(NewinArea, i, key);
  124.           if OK then
  125.             begin
  126.               repeat
  127.                 Seek(nwin_file, i);
  128.                 Read(nwin_file, nwin_rec);
  129.                 if (nwin_rec.status = public) and ExistFile(dirspec+'\'+nwin_rec.name) then
  130.                   begin
  131.                     write_rec;
  132.                     need_sort := True;
  133.                   end;
  134.                 NextKey(NewinArea, i, key);
  135.               until (not OK) or (key <> SearchKey) or brk;
  136.               Close(sort_file);
  137.               if need_sort then
  138.                 not_found := TurboSort(SizeOf(sort_rec), @put_recs, @less_rec, @get_recs)
  139.               else
  140.                 begin
  141.                   {$I-}
  142.                   Close(sort_file) {$I+};
  143.                   if IoResult = 0 then
  144.                     Erase(sort_file);
  145.                 end;
  146.             end
  147.           else
  148.             begin
  149.               WriteLn(dir_file);
  150.               WriteLn(dir_file, 'No files listed for this section.');
  151.               WriteLn(dir_file);
  152.             end;
  153.         end;
  154.     end;
  155.     
  156.     
  157.     procedure Header;
  158.     
  159.     var
  160.       This            : SysmPtr;
  161.       rec             : Integer;
  162.       
  163.     begin
  164.       This := SysmBase;
  165.       while (This <> nil) and (This^.key <> 'G') do
  166.         This := This^.next;
  167.       if This^.key = 'G' then
  168.         begin
  169.           rec := Succ(This^.loc);
  170.           repeat
  171.             Seek(sysm_file, rec);
  172.             Read(sysm_file, sysm_rec);
  173.             Inc(rec);
  174.             if sysm_rec[1] <> ':' then
  175.               WriteLn(dir_file, sysm_rec);
  176.           until EoF(sysm_file) or (sysm_rec[1] = ':');
  177.           WriteLn(dir_file);
  178.         end;
  179.     end;
  180.     
  181.     
  182.     procedure Center(Str : StrStd);
  183.       { Center string on print line }
  184.       
  185.     begin
  186.       WriteLn(dir_file, ' ': ((user_rec.columns-Length(Str)) div 2), Str);
  187.     end;
  188.     
  189.     
  190.   begin                           { sys_dir }
  191.     Close(mesg_file);
  192.     abort := False;
  193.     SetSect(HomName);
  194.     WriteLn(Com);
  195.     Write(Com, 'Enter File Section name where SYSTEM.DIR will be written: ');
  196.     DestName := get_section_name(' ');
  197.     WriteLn(Com);
  198.     if ch <> ETX then
  199.       begin
  200.         WriteLn(Com);
  201.         WriteLn(Com, 'Building system directory...Please wait...');
  202.         KepDrv := SetDrv;
  203.         KepReq := SectReq;
  204.         KepName := SetName;
  205.         FindSect(DestName, TmpDrv, OK);
  206.         if not OK then
  207.           begin
  208.             TmpDrv := HomDrv;
  209.             TmpName := HomName;
  210.           end
  211.         else
  212.           begin
  213.             if DestName = 'SYSTEM' then
  214.               TmpName := HomName
  215.             else
  216.               begin
  217.                 TmpName := TmpDrv;
  218.                 if (Length(HomName) > 3) and (TmpDrv = HomDrv) then
  219.                   begin
  220.                     TmpName := TmpName+Copy(HomName, 4, Length(HomName));
  221.                     TmpName := TmpName+'\';
  222.                   end;
  223.                 TmpName := TmpName+DestName;
  224.               end;
  225.           end;
  226.         Assign(dir_file, TmpName+'\'+'SYSTEM.DIR');
  227.         {$I-}
  228.         Rewrite(dir_file) {$I+} ;
  229.         OK := (IoResult = 0);
  230.         if OK then
  231.           begin
  232.             Header;
  233.             Center('Complete System Directory Listing');
  234.             Center('as of');
  235.             GetTAD(t);
  236.             Str := FormTAD(t);
  237.             Center(Str);
  238.             This := SectBase;
  239.             while (This <> nil) and (not brk) and (Online) do
  240.               begin
  241.                 if This^.SectAccs <= val_acc then
  242.                   begin
  243.                     SectReq := This^.SectName;
  244.                     SetDrv := This^.SectDrive;
  245.                     SetName := This^.SectDrive+':\';
  246.                     if (Length(HomName) > 3) and (SetName = HomDrv) then
  247.                       begin
  248.                         SetName := SetName+Copy(HomName, 4, Length(HomName));
  249.                         SetName := SetName+'\';
  250.                       end;
  251.                     if Pos(':', This^.SectName) = 2 then
  252.                       SetName := SetName+Copy(This^.SectName, 3, Length(This^.SectName))
  253.                     else
  254.                       SetName := SetName+This^.SectName;
  255.                     write_list;
  256.                   end;            {section<access}
  257.                 This := This^.next
  258.               end;                {this<>nil}
  259.             Close(dir_file);
  260.             SetSect(HomName);
  261.             SectReq := KepReq;
  262.             SetDrv := KepDrv;
  263.             SetName := KepName;
  264.             ReadDir(DirEntries, DirSpace, DirBase)
  265.           end;                    {file opened ok}
  266.         WriteLn(Com);
  267.       end;
  268.     if ExistFile('SORT.TMP') then
  269.       Erase(sort_file);
  270.     Reset(mesg_file);
  271.   end;
  272.   
  273.   
  274.   procedure purge_files;
  275.     { Purge various system files of extraneous records }
  276.     
  277.   var
  278.     done            : Boolean;
  279.     ch_sel          : Char;
  280.     age, cur_date   : Real;
  281.     t               : tad_array;
  282.     
  283.     
  284.     procedure purge_log;
  285.       { Purge the log file of all records }
  286.       
  287.     begin
  288.       WriteLn(Com, 'Purging the LOG file...');
  289.       Seek(logr_file, 0);
  290.       Read(logr_file, logr_rec);
  291.       Close(logr_file);
  292.       Rewrite(logr_file);
  293.       Write(logr_file, logr_rec);
  294.       FlushAny(logr_file);
  295.       WriteLn(Com);
  296.       log(11, 'Log file');
  297.     end;
  298.     
  299.     
  300.     procedure purge_message;
  301.       { Purge deleted messages }
  302.       
  303.     const
  304.       col_width       = 6;
  305.       
  306.     var
  307.       i, col_count,
  308.       col_limit,
  309.       req_size        : Integer;
  310.       size            : Real;
  311.       nsum_file       : file of summ_list;
  312.       nmsg_file       : file of mesg_list;
  313.       
  314.     begin
  315.       size := FileSize(summ_file)*80.0;
  316.       req_size := Trunc(size/1024.0);
  317.       if Frac(size/1024.0) > 0 then
  318.         req_size := req_size+2;
  319.       size := FileSize(mesg_file)*73.0;
  320.       req_size := req_size+Trunc(size/1024.0);
  321.       if Frac(size/1024.0) > 0 then
  322.         req_size := req_size+2;
  323.       if (diskfree(Ord(Upcase(HomDrv[1]))-64) div 1024) > req_size then
  324.         begin
  325.           col_limit := max(1, user_rec.columns div col_width);
  326.           WriteLn(Com, 'Purging the MESSAGE files...');
  327.           Assign(nsum_file, summ_name+'.$$$');
  328.           Assign(nmsg_file, mesg_name+'.$$$');
  329.           Rewrite(nsum_file);
  330.           Rewrite(nmsg_file);
  331.           Seek(summ_file, 0);
  332.           Read(summ_file, summ_rec); { Copy message counter to new file }
  333.           Write(nsum_file, summ_rec);
  334.           col_count := 0;
  335.           while not EoF(summ_file) do
  336.             with summ_rec do
  337.               begin
  338.                 Read(summ_file, summ_rec);
  339.                 age := cur_date-greg_to_jul(date[3], date[4], date[5]);
  340.                 if ((status = deleted) or (age > unr_days) or ((status = Seen) and (age >
  341.                   rea_days))) and
  342.                 (num_prev <> 255) then
  343.                   begin           {delete message}
  344.                     if (0 = col_count mod col_limit) then
  345.                       WriteLn(Com);
  346.                     Write(Com, num:col_width);
  347.                     Inc(col_count)
  348.                   end
  349.                 else
  350.                   begin           {save message}
  351.                     Seek(mesg_file, st_rec);
  352.                     st_rec := FileSize(nmsg_file);
  353.                     Write(nsum_file, summ_rec);
  354.                     for i := 1 to size do
  355.                       begin
  356.                         Read(mesg_file, mesg_rec);
  357.                         Write(nmsg_file, mesg_rec)
  358.                       end
  359.                   end
  360.               end;
  361.               
  362.           Close(summ_file);
  363.           Close(mesg_file);
  364.           Close(nsum_file);
  365.           Close(nmsg_file);
  366.           
  367.           Erase(summ_file);
  368.           Erase(mesg_file);
  369.           Rename(nsum_file, summ_name+ext);
  370.           Rename(nmsg_file, mesg_name+ext);
  371.           
  372.           Reset(summ_file);
  373.           Reset(mesg_file);
  374.           
  375.           mesg_build_index(AreaSet);
  376.           WriteLn(Com);
  377.           log(11, 'Msg file');
  378.         end
  379.       else
  380.         WriteLn(Com, 'Insufficient Disk space to purge MESSAGE files.');
  381.     end;
  382.     
  383.     
  384.     procedure purge_newin;
  385.       { Purge deleted newin records }
  386.       
  387.     var
  388.       new_nwin_file   : file of nwin_list;
  389.       req_size        : Integer;
  390.       size            : Real;
  391.       i               : LongInt;
  392.       
  393.     begin
  394.       size := FileSize(nwin_file)*120.0;
  395.       req_size := Trunc(size/1024.0);
  396.       if Frac(size/1024.0) > 0 then
  397.         req_size := req_size+2;
  398.       if (diskfree(Ord(Upcase(HomDrv[1]))-64) div 1024) > req_size then
  399.         begin
  400.           WriteLn(Com, 'Purging the NEWIN file...');
  401.           Assign(new_nwin_file, nwin_name+'.$$$');
  402.           Rewrite(new_nwin_file);
  403.           Seek(nwin_file, 0);
  404.           repeat
  405.             {$I-}
  406.             Read(nwin_file, nwin_rec) {$I+} ;
  407.             if IoResult = 0 then
  408.               if nwin_rec.status <> deleted then
  409.                 Write(new_nwin_file, nwin_rec)
  410.           until EoF(nwin_file);
  411.           Close(nwin_file);
  412.           Close(new_nwin_file);
  413.           
  414.           Erase(nwin_file);
  415.           Rename(new_nwin_file, nwin_name+ext);
  416.           
  417.           Reset(nwin_file);
  418.           Seek(nwin_file, 1);
  419.           
  420.           if ExistFile(area_indx+ext) then
  421.             EraseIndex(NewinArea);
  422.           if ExistFile(name_indx+ext) then
  423.             EraseIndex(NewinName);
  424.             
  425.           MakeIndex(NewinArea, area_indx+ext, 12, Duplicates);
  426.           MakeIndex(NewinName, name_indx+ext, 12, Duplicates);
  427.           WriteLn(Com, 'Indexing the NEWIN file...');
  428.           with nwin_rec do
  429.             begin
  430.               i := 1;
  431.               while (not EOF(nwin_file)) do
  432.                 begin
  433.                   Read(nwin_file, nwin_rec);
  434.                   AddKey(NewinArea, i, sectn);
  435.                   AddKey(NewinName, i, name);
  436.                   Inc(i);
  437.                 end;
  438.             end;
  439.           WriteLn(Com);
  440.           log(11, 'Newin');
  441.         end
  442.       else
  443.         WriteLn(Com, 'Insufficient disk space to purge NEWIN file.');
  444.     end;
  445.     
  446.     
  447.     procedure purge_user;
  448.       { Purge outdated users }
  449.       
  450.     var
  451.       i               : Integer;
  452.       temp_user_loc   : LongInt;
  453.       Str             : StrTAD;
  454.       key             : StrName;
  455.       temp_user_rec   : user_list;
  456.       
  457.     begin
  458.       WriteLn(Com, 'Purging the USER file...');
  459.       temp_user_loc := 1;
  460.       while temp_user_loc < FileLen(DatF) do
  461.         with temp_user_rec do
  462.           begin
  463.             GetRec(DatF, temp_user_loc, temp_user_rec);
  464.             age := cur_date-greg_to_jul(laston[3], laston[4], laston[5]);
  465.             if ((used = 0) and (not test_bit(temp_user_rec.Flags, 5)) and (((age > unv_days)
  466.               and
  467.               (access < val_acc)) or ((age > val_days) and (access >= val_acc)))) then
  468.               begin               {purge the guy}
  469.                 key := pad(ln, len_ln)+pad(fn, len_fn);
  470.                 DeleteKey(IdxF, temp_user_loc, key);
  471.                 if OK then
  472.                   begin
  473.                     DeleteRec(DatF, temp_user_loc);
  474.                     Str := FormTAD(laston);
  475.                     WriteLn(Com);
  476.                     Write(Com, key, ' ', access, ' ', Str);
  477.                     for i := 1 to Pred(FileSize(summ_file)) do
  478.                       { Delete messages pertaining to user }
  479.                       begin
  480.                         Seek(summ_file, i);
  481.                         Read(summ_file, summ_rec);
  482.                         if ((summ_rec.user_to = temp_user_loc) or (summ_rec.user_from =
  483.                           temp_user_loc)) then
  484.                           begin
  485.                             WriteLn(Com);
  486.                             mesg_delete;
  487.                           end;
  488.                       end;
  489.                     {now clear newin file references}
  490.                     Seek(nwin_file, 1);
  491.                     repeat
  492.                       {$I-}
  493.                       Read(nwin_file, nwin_rec); {$I+}
  494.                       if IoResult = 0 then
  495.                         begin
  496.                           if nwin_rec.user = temp_user_loc then
  497.                             begin
  498.                               nwin_rec.user := 0;
  499.                               Seek(nwin_file, Pred(FilePos(nwin_file)));
  500.                               Write(nwin_file, nwin_rec);
  501.                             end;
  502.                         end;
  503.                     until EoF(nwin_file);
  504.                     {now finally, the log file}
  505.                     Seek(logr_file, 1);
  506.                     repeat
  507.                       {$I-}
  508.                       Read(logr_file, logr_rec); {$I+}
  509.                       if IoResult = 0 then
  510.                         begin
  511.                           if logr_rec.user = temp_user_loc then
  512.                             begin
  513.                               logr_rec.user := 0;
  514.                               Seek(logr_file, Pred(FilePos(logr_file)));
  515.                               Write(logr_file, logr_rec);
  516.                               FlushAny(logr_file);
  517.                             end;
  518.                         end;
  519.                     until EoF(logr_file);
  520.                   end;
  521.               end;
  522.             Inc(temp_user_loc)
  523.           end;
  524.       WriteLn(Com);
  525.       log(11, 'Users');
  526.     end;
  527.     
  528.   begin                           {PURGE FILES}
  529.     GetTAD(t);
  530.     SetSect(HomName);
  531.     cur_date := greg_to_jul(t[3], t[4], t[5]);
  532.     done := False;
  533.     repeat
  534.       st := prompt('File(s) to purge <A><L><M><N><U><Q><?> ', 80, 'ES?');
  535.       if Length(st) = 1 then
  536.         ch_sel := st[1]
  537.       else
  538.         ch_sel := '?';
  539.       case ch_sel of
  540.         'A' :
  541.           begin
  542.             if (not macro_in_progress) then
  543.               OK := ask('Do you want to purge ALL files', 'Y');
  544.             if macro_in_progress or OK then
  545.               begin
  546.                 purge_log;
  547.                 purge_newin;
  548.                 purge_user;
  549.                 purge_message;
  550.                 done := True
  551.               end;
  552.           end;
  553.         'L' :
  554.           if macro_in_progress then
  555.             purge_log
  556.           else if ask('Do you want to purge the LOG file', 'Y') then
  557.             purge_log;
  558.         'M' :
  559.           if macro_in_progress then
  560.             purge_message
  561.           else if ask('Do you want to purge the MESSAGE files', 'Y') then
  562.             purge_message;
  563.         'N' :
  564.           if macro_in_progress then
  565.             purge_newin
  566.           else if ask('Do you want to purge the NEWIN file', 'Y') then
  567.             purge_newin;
  568.         'U' :
  569.           if macro_in_progress then
  570.             purge_user
  571.           else if ask('Do you want to purge the USER file', 'Y') then
  572.             purge_user;
  573.         'Q' :
  574.           done := True
  575.       else
  576.         WriteLn(Com, '<A>ll, <L>og, <M>essage, <N>ewin, <U>ser, <Q>uit');
  577.       end;
  578.     until (done) or (not Online);
  579.   end;
  580.   
  581.   
  582. end.                              { of SYSOP2.PAS}
  583. 
  584.